﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Ket_noi_toi_VPP_bang_mo_hinh_ba_lop.Connection;

namespace Ket_noi_toi_VPP_bang_mo_hinh_ba_lop.DAL
{
    class NhaCungCap
    {
        private dbConnection Conn;

        public NhaCungCap()
        {
            Conn = new dbConnection();
        }

        public bool Insert(string TenNCC,string DiaChi,string DienThoai,string Email)
        { 
            SqlParameter[] sqlPara=new SqlParameter[4];
            sqlPara[0] = new SqlParameter("@TenNCC",SqlDbType.NVarChar,30);                        
            sqlPara[0].Value = Convert.ToString(TenNCC);
            sqlPara[1] = new SqlParameter("@DiaChi", SqlDbType.NVarChar,50);
            sqlPara[1].Value = Convert.ToString(DiaChi);           
            sqlPara[2] = new SqlParameter("@DienThoai", SqlDbType.VarChar,20);
            sqlPara[2].Value = Convert.ToString(DienThoai);            
            sqlPara[3] = new SqlParameter("@Email", SqlDbType.NVarChar,30);
            sqlPara[3].Value = Convert.ToString(Email);
            return Conn.executeInsertProcedureQuery("Insert_NCC", sqlPara);
        }

        public bool Update(int MaNCC, string TenNCC, string DiaChi, string DienThoai, string Email)
        {
            SqlParameter[] sqlPara = new SqlParameter[5];
            sqlPara[0] = new SqlParameter("@MaNCC", SqlDbType.Int);
            sqlPara[0].Value = Convert.ToString(MaNCC);
            sqlPara[1] = new SqlParameter("@TenNCC", SqlDbType.NVarChar, 30);
            sqlPara[1].Value = Convert.ToString(TenNCC);
            sqlPara[2] = new SqlParameter("@DiaChi", SqlDbType.NVarChar, 50);
            sqlPara[2].Value = Convert.ToString(DiaChi);
            sqlPara[3] = new SqlParameter("@DienThoai", SqlDbType.VarChar, 20);
            sqlPara[3].Value = Convert.ToString(DienThoai);
            sqlPara[4] = new SqlParameter("@Email", SqlDbType.NVarChar, 30);
            sqlPara[4].Value = Convert.ToString(Email);
            return Conn.executeInsertProcedureQuery("Update_NCC", sqlPara);
        }
        
        public bool Delete(int MaNCC)
        { 
            SqlParameter[] sqlPara=new SqlParameter[1];
            sqlPara[0] = new SqlParameter("@MaNCC",SqlDbType.Int);
            sqlPara[0].Value = Convert.ToString(MaNCC);
            return Conn.executeUpdateProcedureQuery("Delete_NCC",sqlPara);
        }
        
        public DataTable SelectAll()
        {
            return Conn.excuteSelectProcedureQuery("SelectAll_NCC");
        }

        public DataTable SelectID(int MaNCC)
        { 
            SqlParameter[] sqlPara=new SqlParameter[1];
            sqlPara[0] = new SqlParameter("@MaNCC",SqlDbType.Int);
            sqlPara[0].Value = Convert.ToString(MaNCC);
            return Conn.excuteSelectProcedureQuery("SelectID_NCC",sqlPara);
        }
    }
}
